////////////////////////////////////【富文本编辑器js】////////////////////////////////////////////////

var editor = new wangEditor('#editor');
editor.customConfig.uploadImgServer = '/admin/fileUpload/editorUpload2';
editor.customConfig.uploadFileName = 'file';
editor.customConfig.uploadImgTimeout = 10000;
editor.customConfig.uploadImgMaxSize = 50 * 1024 * 1024;
editor.customConfig.uploadImgHeaders = {
	'X-Requested-With': 'XMLHttpRequest',
}

/**
 * 解决多图片上传，顺序错误问题
 */
editor.customConfig.uploadImgHooks = {
    customInsert: function (insertImg, result, editor) {
    	for ( var i in result.data) {
    		editor.cmd.do('insertHTML', '<img src="' + result.data[i] + '" style="max-width:100%;"/>');
		}
    }
}

editor.create();

/**
 * 富文本编辑器设置内容
 * @param content 需要设置的内容
 * @returns
 */
function setContent(content) {
	if (editor == null || editor == undefined) {
		editor.create();
	}
	editor.txt.html(content);
}

/**
 * 富文本编辑器追加内容
 * @param content 追加的内容
 * @returns
 */
function appendContent(content) {
	if (editor == null || editor == undefined) {
		editor.create();
	}
	editor.txt.html(content);
}

/**
 * 清除内容
 * @returns
 */
function clearContent() {
	if (editor == null || editor == undefined) {
		editor.create();
	}
	editor.txt.clear();
}

/**
 * 获取html内容
 */
function getContentHtml() {
	if (editor == null || editor == undefined) {
		editor.create();
	}
	return editor.txt.html();
}

/**
 * 获取纯文本内容
 */
function getContentText() {
	if (editor == null || editor == undefined) {
		editor.create();
	}
	return editor.txt.text();
}